package ControlLayer;
import ModelLayer.*;


/**
 * Write a description of class PersonController here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class PersonController
{
    // instance variables - replace the example below with your own
    private PersonContainer personContainer;

    /**
     * Constructor for objects of class PersonController
     */
    public PersonController()
    {
        personContainer = personContainer.getInstance();
    }

    
     
     public void createPrivateCustomer(String name, String address, int phoneNumber, String city, int ZIPCode, int maxCredit)
     {
         PrivateCustomer personX = new PrivateCustomer();
         personX.setName(name);
         personX.setAddress(address);
         personX.setPhoneNumber(phoneNumber);
         personX.setCity(city);
         personX.setZIPCode(ZIPCode);
         personX.setMaxCredit(maxCredit); 
         personContainer.createPerson(personX);
     }
     
     
     public void createBusinessCustomer(String name, String address, int phoneNumber, String city, int ZIPCode, int maxCredit, int CVRNumber)
     {
         BusinessCustomer personX = new BusinessCustomer(CVRNumber);
         personX.setName(name);
         personX.setAddress(address);
         personX.setPhoneNumber(phoneNumber);
         personX.setCity(city);
         personX.setZIPCode(ZIPCode);
         personX.setMaxCredit(maxCredit); 
         personContainer.createPerson(personX);        
     }
     
     public void createUnregisteredCustomer()
     {
     
        
     }
     
     
     public void createSalesman(String name, String address, int phoneNumber, String city, int ZIPCode, String loginName, String password, int userLevel)
     {
         Salesman personX = new Salesman();
         personX.setName(name);
         personX.setAddress(address);
         personX.setPhoneNumber(phoneNumber);
         personX.setCity(city);
         personX.setZIPCode(ZIPCode);
         personX.setLoginName(loginName);
         personX.setPassword(password); 
         personX.setUserLevel(userLevel);
         personContainer.createPerson(personX);          
         
     }
     
     
     public void createManager(String name, String address, int phoneNumber, String city, int ZIPCode, String loginName, String password, int userLevel)
     {
         Manager personX = new Manager();
         personX.setName(name);
         personX.setAddress(address);
         personX.setPhoneNumber(phoneNumber);
         personX.setCity(city);
         personX.setZIPCode(ZIPCode);
         personX.setLoginName(loginName);
         personX.setPassword(password); 
         personX.setUserLevel(userLevel);
         personContainer.createPerson(personX);      
     }
     
     
     public void createWarehouseEmployee(String name, String address, int phoneNumber, String city, int ZIPCode, String loginName, String password, int userLevel)
     {
         WarehouseEmployee personX = new WarehouseEmployee();
         personX.setName(name);
         personX.setAddress(address);
         personX.setPhoneNumber(phoneNumber);
         personX.setCity(city);
         personX.setZIPCode(ZIPCode);
         personX.setLoginName(loginName);
         personX.setPassword(password); 
         personX.setUserLevel(userLevel);
         personContainer.createPerson(personX);
         
     }
     

        public void deletePerson(int phoneNumber)
     {
         personContainer.deletePerson(phoneNumber);
         
     }
     
        public void updatePersonName(int phoneNumber, String name)
        {
            personContainer.updatePersonName(phoneNumber, name);
        }
        
        public void updatePersonPhoneNumber(int phoneNumber, int newPhoneNumber)
        {
            personContainer.updatePersonPhoneNumber(phoneNumber, newPhoneNumber);
            
        }
        
        public void updatePersonAddress(int phoneNumber, String address)
        {
            personContainer.updatePersonAddress(phoneNumber, address);
        }
        
        public void updatePersonCity(int phoneNumber, String city)
        {
            personContainer.updatePersonCity(phoneNumber, city);
        }
        
        public void updatePersonZIPCode(int phoneNumber, int ZIPCode)
        {
            personContainer.updatePersonZIPCode(phoneNumber, ZIPCode);            
        }
        
        public void updatePersonMaxCredit(int phoneNumber, int maxCredit)
        {
            personContainer.updatePersonMaxCredit(phoneNumber, maxCredit);               
        }
        
        public void updatePersonLoginName(int phoneNumber, String loginName)
        {
            personContainer.updatePersonLoginName(phoneNumber, loginName);
        }        
        public void updatePersonPassword(int phoneNumber, String password)
        {
            personContainer.updatePersonPassword(phoneNumber, password) ;
        }                
        public void updatePersonUserLevel(int phoneNumber, int userLevel)
        {
            personContainer.updatePersonUserLevel(phoneNumber, userLevel);
            
        }                
        public void updatePersonPayment(int phoneNumber, int payment)
        {
            personContainer.updatePersonPayment(phoneNumber, payment);
            
        }                
     
     public Person findPerson(int phoneNumber) throws Exception
     {
         Person newPerson = personContainer.findPerson(phoneNumber);
         if(newPerson == null)
         {
            throw new Exception("Customer not found");    
         }
         return newPerson;
     }
     
    public String checkObjectType(Person newPerson)
    {
        String type = "";
        if(newPerson instanceof PrivateCustomer)
        {
            type = "PrivateCustomer";
        }
        if(newPerson instanceof BusinessCustomer)
        {
            type="BusinessCustomer";
        }
        if(newPerson instanceof WarehouseEmployee)
        {
            type="WarehouseEmployee";
        }
        if(newPerson instanceof Manager)
        {
            type = "Manager";
        }
        if(newPerson instanceof Salesman)
        {
            type="Salesman";
        }
        return type;
    }
    
}